<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
  <%@ taglib prefix="s" uri="/struts-tags" %>

 <head>
	<meta charset="utf-8">
	<title>Order History</title>

	 <script charset="UTF-8" language="javascript" type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.ui.datepicker.js"></script>


	<script>
	$(function() {
		$( "#endDate" ).datepicker();
		$( "#startDate" ).datepicker();
	});

    $(document).ready(function()
{
	$( "#name" ).autocomplete({
		source: "<s:url action="suggest" namespace="/customers"/>",
		delay: 10,
		autoFocus: false,
		minLength: 0
	});
	});

	</script>
</head>
<form action="<s:url action="quicklist"/>" method="post" accept-charset="utf-8" id="filter_form">

<div id="report_date_range_simple">
		<input type="radio" checked="checked" value="0" id="simple_radio" name="dateFilterType">
		<select id="report_date_range_simple" name="dateRange">
            <option value="0" <c:if test="${dateRange == 0 }">selected="selected"</c:if> >Today</option>
            <option value="1" <c:if test="${dateRange == 1 }">selected="selected"</c:if> >Yesterday</option>
            <option value="2" <c:if test="${dateRange == 2 }">selected="selected"</c:if> >Last 7 Days</option>
            <option value="3" <c:if test="${dateRange == 3 }">selected="selected"</c:if> >This Month</option>
            <option value="4" <c:if test="${dateRange == 4 }">selected="selected"</c:if> >Last Month</option>
            <option value="5" <c:if test="${dateRange == 5 }">selected="selected"</c:if> >This Year</option>
            <option value="6" <c:if test="${dateRange == 6 }">selected="selected"</c:if>>Last Year</option>
            <option value="7"<c:if test="${dateRange == 7 }">selected="selected"</c:if> >All Time</option>
        </select>
</div>
<div id="report_date_range_complex">
		<input type="radio" value="1" id="complex_radio" name="dateFilterType">
	    <input type="text" name="startDate" id="startDate">
						-
          <input type="text" name="endDate" id="endDate"/>

      <input type="submit" name="filter" id="submit" value="filter"/>
</div>
<div class="field_row clearfix">
<label for="customerId" class="required wide">Customer Name:</label>	<div class='form_field'>
	<input type="text" id="name" name="customerId" value="${customerId}" id="name"  />
	<input type="text" id="city" name="city" value="${city}" id="name"  />
	</div>
</div>
</form>
  <table id="title_bar">
                	<tbody><tr>
                		<td id="title_icon">
                			<img alt="title icon" src="${pageContext.request.contextPath}/images/menubar/customers.png">
                		</td>
                		<td id="title">
                			List of Sales
                			</td>
                		<td id="title_search">
                			<form id="search_form" accept-charset="utf-8" method="post" action="${pageContext.request.contextPath}/customers/search">
                			<input type="text" id="search" name="search" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
                				<img id="spinner" alt="spinner" src="${pageContext.request.contextPath}/images/spinner_small.gif">
                			</form>
                		</td>
                	</tr>
                	<tr>
                    <td id="commands" colspan="2">
                                    					<a title="New Employee" class=" none new" href="${pageContext.request.contextPath}/sales/new.ps">New Order</a>
                                    	</td>

                	</tr>
                </tbody></table>
<table style="width: 100%;" id="contents">
	<tbody><tr>
		<td id="item_table">
			<table id="suspended_sales_table">
				<tbody><tr>
					<th>ID#</th>
					<th>Date</th>
					<th>Comments</th>
					<th>Total Amount</th>
					<th>Items Purchased</h>
					<th>Payment</th>
					<th>Due Amount</th>
					<th>Sold By</th>
					<th>Sold To</th>

					<th>Receipt</th>

				</tr>
        <jsp:useBean id="dateValue" class="java.util.Date" />

<c:forEach var="item" items="${orderEntities}">
            <tr>
						<td>${item.id}</td>
                         <jsp:setProperty name="dateValue" property="time" value="${item.orderDate}" />
                       	<td><fmt:formatDate pattern="dd/MM/yyyy hh:mm aaa"  value="${dateValue}" /></td>
						<td>${item.note}</td>
						<td>INR ${item.totalAmount}</td>
						<td>${fn:length(item.itemList)}</td>
						 <td>INR ${item.totalAmount-item.dueAmount}</td>
						<td>INR ${item.dueAmount}</td>
						<td> ${item.employee.name}</td>
                        <td> ${item.customer.name},${item.customer.city}</td>
						<td>
							<form id="form_receipt_suspended_sale" method="get" accept-charset="utf-8" action="${pageContext.request.contextPath}/receipts/orderreceipt.ps">
							<input type="hidden" value="${item.id}" name="id">
							<input type="submit" class="submit_button float_right" id="submit_receipt" value="Receipt" name="submit">
							</form>
						</td>

					</tr>
            </c:forEach>

             <tr><td colspan="2">Total Order</td><td>${totalOrderAmount}</td> </tr>

                 <tr><td colspan="2">Amount Paid</td><td>${ordersTotalPaymentAmount}</td> </tr>
                <tr><td colspan="2">Total Due Amount</td><td>${totalDueAmount}</td> </tr>


							</tbody></table>
		</td>
	</tr>
</tbody></table>